<template>
  <el-form label-width="70px" class="login" :model="form" :rules="rules">
    <h3 class="login_title">系统登录</h3>
    <el-form-item label="用户名" prop="username">
      <el-input v-model="form.username" placeholder="请输入账号"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="username">
      <el-input
        type="password"
        v-model="form.password"
        placeholder="请输入密码"
      ></el-input>
    </el-form-item>
    <el-form-item>
      <el-button @click="submit" class="subit" type="primary">登录</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
// import Mock from 'mockjs'
// import Cookie from 'js-cookie'
// import { getMenu } from '../api'
import { reactive, ref, getCurrentInstance } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
export default {
  setup() {
    const { proxy } = getCurrentInstance()
    const store = useStore()
    const router = useRouter()
    const form = reactive({
      username: '',
      password: '',
    })
    const rules = ref({
      username: [{ required: true, trigger: 'blur', message: '请输入用户名' }],
      password: [{ required: true, trigger: 'blur', message: '请输入密码' }],
    })
    const submit = async () => {
      const res = await proxy.$api.getMenu(form)
      console.log(res)
      store.commit('setMenu', res.menu)
      store.commit('addMenu', router)
      store.commit('setToken', res.token)
      router.push({
        name: 'home1',
      })
    }

    return {
      form,
      rules,
      submit,
    }
  },
}
</script>

<style lang="less" scoped>
.login {
  width: 350px;
  padding: 35px 35px 15px 35px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
  box-sizing: border-box;
  margin: 100px auto;
  .el-input {
    width: 195px;
  }
  .login_title {
    margin: 0 auto 40px auto;
    text-align: center;
    color: #505458;
  }
  .subit {
    margin: 10px auto 0 auto;
    margin-top: 10px;
    margin-left: 105px;
  }

  :deep(.el-form-item :nth-child(3)) {
    .el-form-item__content {
      margin-left: 0;
    }
  }
}
</style>
